Skip to content

chore: user office experiment workflow - #1391

Merged
yoganandaness merged 89 commits into
developfrom
SWAP-5222-user-office-experiment-workflow-improvement
Jul 21, 2026
Merged

chore: user office experiment workflow#1391
yoganandaness merged 89 commits into
developfrom
SWAP-5222-user-office-experiment-workflow-improvement

Conversation

@yoganandaness

@yoganandaness yoganandaness commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

Description

This PR implements comprehensive workflow improvements for experiment safety management and integrates the new workflow data structures across the application. It includes support for manual status changes, enhanced workflow engine with guards, and updates to frontend components for better workflow status handling.

Motivation and Context

The experiment safety workflow needs to support more sophisticated status transitions and manual interventions similar to the proposal workflow. This requires integrating the new workflow data structures (from SWAP-4949) into the experiment safety module and implementing proper authorization checks, event handling, and UI components for managing experiment safety workflow statuses.

Related Issue: SWAP-5222

How Has This Been Tested

  • Unit tests updated and fixed for new workflow structures
  • E2E tests updated for:
    • Experiment safety review workflows
    • Instrument settings with new workflow statuses
    • Settings workflow management
  • Integration tests for workflow guards and state transitions
  • Manual testing of experiment safety status changes
  • Fixes applied to resolve flaky tests

Changes

Backend Changes

  • Database Migrations:

    • 0208_MigrateOldWorkflowsToNewDataStructures.sql - Migrates existing workflows to new data structures
    • 0211_ExperimentSafetyWorkflowStatusNotNull.sql - Makes experiment_safety.workflow_status_id non-nullable with AWAITING_ESF backfill
  • Workflow Engine & Guards:

    • Added experiment workflow engine (src/workflowEngine/experiment.ts)
    • Implemented new guards for experiment ESF status checking
    • Enhanced workflow state machine with proper transitions
  • Data Sources:

    • Updated ExperimentDataSource to support workflow status management
    • Enhanced WorkflowDataSource for experiment safety workflows
    • Updated mock implementations for testing
  • Event Handlers:

    • Implemented experiment workflow event handlers
    • Added email and RabbitMQ handlers for experiment status changes
    • Added status action engine for experiment workflows
    • Enhanced proposal workflow event handlers
  • Authorization:

    • Updated ExperimentSafetyAuthorization for workflow-based access control
    • Enhanced authorization checks in workflow operations
  • Mutations:

    • Added ChangeExperimentsSafetyStatusMutation for manual status changes
    • Enhanced experiment and proposal mutations

Frontend Changes

  • Experiment Safety Components:

    • ChangeExperimentSafetyStatus.tsx - New component for manual status changes
    • ExperimentSafety.tsx, ExperimentSafetyPage.tsx, ExperimentSafetyReview.tsx - Updated for new workflow status handling
    • ExperimentSafetyNotification.tsx - Enhanced notifications for workflow changes
  • Workflow Management:

    • WorkflowEditor.tsx, WorkflowView.tsx - Enhanced workflow visualization
    • StatusEventsAndActionsDialog.tsx - Updated for workflow actions
    • workflowUtils.ts - Utility functions for workflow status handling
  • UI Updates:

    • Updated status picker and proposal status components
    • Enhanced questionary step factory for workflow integration
    • Improved experiment and proposal status display tables

E2E Tests

  • Updated Cypress tests for experiment safety review workflows
  • Fixed instrument and settings tests with new workflow structures
  • Enhanced test coverage for workflow status transitions

Depends on

This PR builds upon the workflow overhaul from SWAP-4949. The new workflow data structures and state machine implementation are integrated into the experiment safety module.

Tests included/Docs Updated?

  • I have added tests to cover my changes.
  • All relevant doc has been updated

@yoganandaness
yoganandaness requested a review from a team as a code owner March 2, 2026 08:24
@yoganandaness
yoganandaness requested review from ACLay and removed request for a team March 2, 2026 08:24
@yoganandaness
yoganandaness changed the base branch from develop to SWAP-4949-workflow-overhaul March 2, 2026 08:25
@yoganandaness
yoganandaness removed the request for review from ACLay March 2, 2026 15:43
Base automatically changed from SWAP-4949-workflow-overhaul to develop May 26, 2026 13:37
@yoganandaness

Copy link
Copy Markdown
Contributor Author

@copilot please resolve the merge conflicts. resolve those that you are confident of

Copilot AI commented May 29, 2026

Copy link
Copy Markdown
Contributor

@copilot please resolve the merge conflicts. resolve those that you are confident of

Resolved the merge conflicts and committed the merge resolution in 267e6db25.

@yoganandaness yoganandaness changed the title Swap 5222 user office experiment workflow improvement chore:user office experiment workflow May 29, 2026
@yoganandaness yoganandaness changed the title chore:user office experiment workflow chore: user office experiment workflow Jun 1, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 70 out of 70 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (2)

apps/backend/src/eventHandlers/workflowEntities/proposal/statusActionEngine.ts:33

  • groupByProperties is set to ['workflowId', 'statusId'], but the items being grouped are { proposal, workflowStatusConnectionId } and neither the wrapper nor the Proposal model defines workflowId/statusId. In practice this groups everything together (all keys become undefined), so if multiple different workflowStatusConnectionIds are present you may execute the wrong status actions for some proposals.
    apps/backend/src/eventHandlers/workflowEntities/proposal/statusActionEngine.ts:35
  • The outer Promise.all(...) is not returned/awaited, so callers cannot reliably await completion of status actions, and any rejection inside can become unhandled. Either return/await the Promise.all result (and consider also awaiting/returning the async handlers inside the inner statusActions.map).

Comment thread apps/backend/src/eventHandlers/messageBroker.ts
Comment thread apps/backend/src/eventHandlers/workflowEntities/experiment/statusActionEngine.ts Outdated
@yoganandaness
yoganandaness requested a review from TCMeldrum July 14, 2026 19:58
// NOTE: We need to group the proposals by 'workflow' and 'status' because proposals coming in here can be from different workflows/calls.
const groupByProperties = ['workflowId', 'statusId'];
// NOTE: Here the result is something like: [[proposalsWithWorkflowStatusIdCombination1], [proposalsWithWorkflowStatusIdCombination2]...]
const groupByProperties = ['workflowStatusConnectionId'];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

@jekabs-karklins jekabs-karklins left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I tested also with the staging database and migrations runs well.

@yoganandaness
yoganandaness enabled auto-merge (squash) July 20, 2026 08:35
@yoganandaness

Copy link
Copy Markdown
Contributor Author

@copilot resolve the merge conflicts in this pull request

auto-merge was automatically disabled July 20, 2026 11:32

Head branch was pushed to by a user without write access

@yoganandaness
yoganandaness enabled auto-merge (squash) July 20, 2026 11:33
auto-merge was automatically disabled July 20, 2026 11:33

Head branch was pushed to by a user without write access

Copilot AI commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

Resolved the merge conflicts from develop. The conflict was in ExperimentsTable.tsx — the develop branch added RoleBasedLink and useLocation imports while our branch had added Dialog, DialogContent, Link, useSnackbar, useCallback, and WorkflowStatus. The merged result now includes all of these correctly. Commit: fix: resolve merge conflicts in ExperimentsTable.tsx from develop branch.

@yoganandaness
yoganandaness enabled auto-merge (squash) July 20, 2026 22:44
@yoganandaness
yoganandaness merged commit d0f210d into develop Jul 21, 2026
35 of 36 checks passed
@yoganandaness
yoganandaness deleted the SWAP-5222-user-office-experiment-workflow-improvement branch July 21, 2026 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants